<template>
  <div>
      <el-row type="flex" justify="center">
          <el-col :span='6' >
              
            <el-form label-width="80px"> 
                <el-form-item label="用户名">
                    <el-input v-model="username" placeholder="请输入用户名"></el-input>
                </el-form-item>
                <el-form-item label='密码'>
                    <el-input type="password" v-model="password" placeholder="请输入密码"></el-input>

                </el-form-item>
                <el-form-item >
                    <!-- <el-input v-model="username" placeholder="请输入用户名"></el-input> -->
                        <el-checkbox label="记住用户名"></el-checkbox>
                </el-form-item>
                <el-form-item>
                    <el-button type='primary' @click="login">登陆</el-button>
                    <el-button >注册</el-button>
                </el-form-item>
            </el-form>

          </el-col>
      </el-row>
  </div>
</template>

<script>
export default {
    data(){
        return {
            username:'',
            password:'',

        }
    },
    methods:{
        login(){
            const data={
                username: this.username,
                password:this.password,
            }
            this.axios.post('/login',data).then(resp=>{
                console.log(resp.data);
                if(resp.data.status==200){
                    sessionStorage.setItem('uid',resp.data.id)
                    const callback = this.$route.query.callback
                    if(callback){
                        this.$router.push({'path':callback})
                    }
                    // alert('登陆成功')
                }                
                else{
                    alert('账号或密码错误')
                }
            }).catch(error=>{
                console.log(error)
            })
        }
    }
}
</script>

<style>

</style>